const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const path = require('path')
const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const merge = require('webpack-merge');

function resolve(dir) {
	return path.join(__dirname, dir)
}

module.exports = {
	// title: 'Ionchain Explorer',
	lintOnSave: false,
	productionSourceMap: false,
	devServer: {
		overlay: {
			warnings: false,
			errors: false,
		},
		disableHostCheck: true,
		proxy: {
			'/api': {
				target: 'http://192.168.23.180:8080',
				ws: true,
				changeOrigin: true,
				pathRewrite:{
					'^/api': ''
				}
			},
			'/zhangchaoyin': {
				target: 'http://192.168.22.134:8080',
				ws: true,
				changeOrigin: true,
				pathRewrite:{
					'^/zhangchaoyin': ''
				}
			},
			'/test-server': {
				target: 'http://explore-server-api.1nongfu.com',
				ws: true,
				changeOrigin: true,
				pathRewrite:{
					'^/test-server': ''
				}
			},
			
		}
	},
	chainWebpack: config => {
		const svgRule = config.module.rule('svg');
		svgRule.uses.clear();
		svgRule
		.use('babel-loader')
		.loader('babel-loader')
		.end()
		.use('vue-svg-loader')
		.loader('vue-svg-loader');
	},
	css: {
		loaderOptions: {
		  less: {
			modifyVars: {
			  'primary-color': '#08aeb2',
			  'link-color': '#08aeb2',	
			  'border-radius-base': '2px',
			},
			javascriptEnabled: true,
		  },
		},
	},
	configureWebpack: config => {
		let baseConfig = {
			resolve: {
				alias: {
				}
			},
		}

		if (process.env.NODE_ENV === 'production') {
			return merge(baseConfig, {
				plugins: [
					new BundleAnalyzerPlugin(),
					new webpack.ContextReplacementPlugin(
						/moment[/\\]locale$/,
						/zh-cn/,
						/en-au/,
					),
					new CompressionWebpackPlugin({
						filename: '[path].gz[query]',
						algorithm: 'gzip',
						test: productionGzipExtensions,
						threshold: 2048,
						minRatio: 0.8
					})
				],
				// provide the app's title in webpack's name field, so that
				// it can be accessed in index.html to inject the correct title.
				name: 'ionchain seed',
			})
		}
	}
}